// Shell based interface to the tag client
#include <stdio.h>
#include "tagdefs.h"
#include "getabsmod.h"
#include "client.h"
#include "nPatriciaTrie.h"
#include "linkedlist.h"

int main(int argc,char **argv){
	int i=0;
	linkedlist *lst;
	lst=new linkedlist();
	if (argc>1) {
		
//		for (i=1;i<argc;i++)
//			printf("%d : %s\n",i,argv[i]);
		if (strcmp(argv[1],"add")==0) {
			for (i=3;i<argc;i++)
				lst->add(argv[i]);
			clientaddtags(argv[2],lst);
		}
		else if (strcmp(argv[1],"remove")==0) {
			for (i=3;i<argc;i++)
				lst->add(argv[i]);
			clientremovetags(argv[2],lst);
		}
		else if (strcmp(argv[1],"listtags")==0) {
			lst=clientlisttags(argv[2]);
			while ((lst!=NULL) && (!lst->isEmpty()))
				printf("%s\n",lst->remove());
		}
		else if (strcmp(argv[1],"listfiles")==0) {
			lst=clientlistfiles(argv[2]);
			while ((lst!=NULL) && (!lst->isEmpty()))
				printf("%s\n",lst->remove());
		}

// --------------------------------
// Introduced for debugging purposes		
//
		else if (strcmp(argv[1],"listallfiles")==0) {
			lst=clientlistallfiles();
			while ((lst!=NULL) && (!lst->isEmpty()))
				printf("%s\n",lst->remove());
		}
		else if (strcmp(argv[1],"getslashlist")==0) {
			lst=clientgetslashlist();
			while ((lst!=NULL) && (!lst->isEmpty()))
				printf("%s\n",lst->remove());
		}
		else if (strcmp(argv[1],"listalltags")==0) {
			lst=clientlistalltags();
			while ((lst!=NULL) && (!lst->isEmpty()))
				printf("%s\n",lst->remove());
		}
		else if ( (strcmp(argv[1],FLATSEARCH)==0) ||
			  (strcmp(argv[1],HIERARCHICAL)==0)) {
			linkedlist *tags;
			tags=new linkedlist();
			tags->add(argv[2]);
			lst=clientsearch(argv[1],tags);
			printf("Files :\n");
			while ((lst!=NULL) && (!lst->isEmpty()))
				printf("%s\n",lst->remove());
			printf("Suggestions :\n");
			lst=clientgetsuggestions();
			while ((lst!=NULL) && (!lst->isEmpty()))
				printf("%s\n",lst->remove());
		}
// -----------------------------------
		else if (strcmp(argv[1],"copyfile")==0) {
			clientcopyfile(argv[2],argv[3]);
		}
		else if (strcmp(argv[1],"removefile")==0) {
			clientremovefile(argv[2]);
		}
		else if (strcmp(argv[1],"removerecurse")==0) {
			clientremovefilerecurse(argv[2]);
		}
		else if (strcmp(argv[1],"move")==0) {
			clientmovefile(argv[2],argv[3]);
		}
		else if (strcmp(argv[1],"endserver")==0) {
			clientendserver();
		}
		else {
			printf("Unprocessed command \n");
			for (i=1;i<argc;i++)
				printf("%d : %s\n",i,argv[i]);
		}
	}
	return 0;
}
